(*value _ =
  let angle t = 10. *. t *. t in
   let render () =
   (
     GlClear.clear [ `color ];
     GlMat.load_identity ();
     GlMat.rotate ~angle: (angle (Sys.time ())) ~z:1. ();
     GlDraw.begins `triangles;
     List.iter GlDraw.vertex2 [(-1., -1.);( 0., 1.);( 1., -1.)];
     GlDraw.ends ();
     Glut.swapBuffers () 
    )
   in
  (
   ignore( Glut.init Sys.argv );
   Glut.initDisplayMode ~double_buffer:True ();
   ignore (Glut.createWindow ~title:"OpenGL Demo");
   GlMat.mode `modelview;
   Glut.displayFunc ~cb:render;
   Glut.idleFunc ~cb:(Some Glut.postRedisplay);
   Glut.mainLoop ()
  );*)

module Hex = (*{{{*)
struct
  value width = 48;
  value height = 23;
  value offset = 5;
  value wcenter = width / 2;
  value cheight = 13;
  value hnormal = cheight + offset;
end;(*}}}*)

(*{{{ Window Params *)
value win_width = ref 1200;
value win_height = ref 800;
value win_title = ("Черновой черновик [SDL based]","HellHole");
(* value win_icon_filename = "sites/docroot/favicon.png"; *)

(* value bg_image_filename = "sites/docroot/items/bazuka_ammo.png"; *)
(* value font_filename  = "/usr/share/fonts/thaifonts-scalable/Loma.ttf"; *)
(*}}}*)

value f_width = Hex.width*64; 
value f_height = 64*Hex.hnormal; 
value f_wcenter=f_width/2;
value f_hcenter=f_height/2;

value (min_s_x,min_s_y) = (0,0);
value (max_s_x,max_s_y) = (f_width-win_width.val,f_height-win_height.val);
value scroll_offset = ref (0,0);

value initScreen () =
  (
    Sdlgl.set_attr [ Sdlgl.DEPTH_SIZE 16; Sdlgl.DOUBLEBUFFER True];
    ignore(Sdlvideo.set_video_mode win_width.val win_height.val [`OPENGL; `RESIZABLE]);
(*     let icon   = Sdlloader.load_image win_icon_filename in *)
    (

      Sdlwm.set_caption (fst win_title) (snd win_title);      
(*       Sdlwm.set_icon icon; *)
      Printf.printf  "DRIVER: %s\n" (Sdlvideo.driver_name ());
      let test v = if v then "ЕСТЬ" else "НЕТ" in
      let vi = Sdlvideo.get_video_info () in
      (
        print_endline ("Аппаратная поддержка сурфейсов:      [" ^ (test vi.Sdlvideo.hw_available) ^ "]" );
        print_endline ("Менеджер окон:                       [" ^ (test vi.Sdlvideo.wm_available) ^ "]" );
        print_endline ("Ускоренная отрисовка HW -> HW:       [" ^ (test vi.Sdlvideo.blit_hw) ^ "]" );
        print_endline ("Ускоренная отрисовка HW с color_key: [" ^ (test vi.Sdlvideo.blit_hw_color_key) ^ "]" );
        print_endline ("Ускоренная отрисовка HW с альфой:    [" ^ (test vi.Sdlvideo.blit_hw_alpha) ^ "]" );
        print_endline ("Ускоренная отрисовка SW -> HW:       [" ^ (test vi.Sdlvideo.blit_sw) ^ "]" );
        print_endline ("Ускоренная отрисовка SW с color_key: [" ^ (test vi.Sdlvideo.blit_sw_color_key) ^ "]" );
        print_endline ("Ускоренная отрисовка SW с альфой:    [" ^ (test vi.Sdlvideo.blit_sw_alpha) ^ "]" );
        print_endline ("Ускоренная залика цветом:            [" ^ (test vi.Sdlvideo.blit_fill) ^ "]" );
        print_endline ("Доступно видео памяти:               [" ^ (string_of_int vi.Sdlvideo.video_mem) ^ "]" );
      );

      GlClear.color (44.0 /. 255.0 , 84.0 /. 255.0, 47.0 /. 255.0) ~alpha:1.0;

      Gl.enable `depth_test; 
      GlFunc.depth_func `lequal;


      (* устанавливаем вьюпорт в размерах нашего экрана *)
      GlDraw.viewport ~x:(fst scroll_offset.val) ~y:(snd scroll_offset.val) ~w:win_width.val ~h:win_height.val;

      (* Устанавливаем ортогональное проецирование *)
      GlMat.mode `projection;
      GlMat.load_identity ();

      GlMat.ortho 
        ~x:(0.0,float_of_int win_width.val)
        ~y:(float_of_int win_height.val,0.0)
        ~z:(-.1., 1.);

      (* возвращаемся к модельвью из проекции *)
      GlMat.mode `modelview;
      GlMat.load_identity ();
    );
  );
(*}}}*)

value _ =
  (
(*    Random.self_init();

    Sdl.init [`VIDEO];
    at_exit Sdl.quit;

    Sdlttf.init ();
    at_exit Sdlttf.quit;

    (* создаем окно *)
    initScreen ();*)

    let angle t = 10. *. t *. t in
    let render () =
    (
      GlClear.clear [ `color ];
      GlMat.load_identity ();
      GlMat.rotate ~angle: (angle (Sys.time ())) ~z:(angle (Sys.time ())) ();
      GlDraw.begins `triangles;
(*         List.iter(fun (x,y) -> GlDraw.vertex3 (x,y,0.0))[(-1., -1.);( 0., 1.);( 1., -1.)]; *)
        List.iter(fun (x,y) -> GlDraw.vertex3 (x,y,0.0))[(2., -1.);( 0., 1.);( 1., -1.)];
      GlDraw.ends ();
      Glut.swapBuffers () 
    )
    in
    (
      ignore( Glut.init Sys.argv ); 
      Glut.initDisplayMode ~double_buffer:True ();
      ignore (Glut.createWindow ~title:"OpenGL Demo");
      GlMat.mode `modelview;
      Glut.displayFunc ~cb:render;
      Glut.idleFunc ~cb:(Some Glut.postRedisplay); 
      Glut.mainLoop ()
    )
  );